package trabalhothreads;

import java.util.Timer;
import java.util.TimerTask;

public class PortaEntrada extends Thread implements Runnable {

    private Banco banco;
    private Timer timer;
    private int tempoAberto;
    private int quantCaixas;
    
    PortaEntrada(Banco banco, int i) {
        this.tempoAberto = i;
        this.banco = banco;
        timer = new Timer();
        timer.schedule(new Lembrete(), tempoAberto);
        new Thread(this, "PortaEntrada").start();
        banco.iniciaAtendimento();
    }

    public void run() {
        while (banco.isBancoAberto()) {
            banco.getFila().put();
        }
    }

    private class Lembrete extends TimerTask {

        public void run() {
            System.out.println("Banco Fechou!**************************************************************************");
            banco.setBancoAberto(false);
            timer.cancel();
        }
    }
}